<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>处方发药</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta content="telephone=no" name="format-detection">
    <meta name="x5-fullscreen" content="true">
    <meta name="full-screen" content="yes">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_363663_xo7863s0yfmbzkt9.css">
    <link rel="stylesheet" href="plugins/weui/weui.min.css">
    <link rel="stylesheet" href="plugins/jquery-weui/css/jquery-weui.css">
    <link rel="stylesheet" href="plugins/swiper/css/swiper.min.css">
    <link rel="stylesheet" href="css/style.css">
    <!--basis script-->
    <script src="plugins/adaptive.js/adaptive.js"></script>
    <script src="plugins/jquery/jquery.min.js"></script>
    <script src="plugins/weui/weui.js"></script>
    <script src="plugins/jquery-weui/js/jquery-weui.min.js"></script>
    <script src="plugins/fastclick/fastclick.js"></script>
    <script src="plugins/vue/vue.js" th:src="@{/static/plugins/vue/vue.js}"></script>
    <script src="plugins/vue/ajax-tool.js" th:src="@{/static/plugins/vue/ajax-tool.js}"></script>
</head>
<body>
<div class="view has-tabbar">
    <div class="page" id="prescription-drugs-detail">
        <div class="weui-panel weui-panel_access info-panel">
            <div class="weui-panel__bd">
                <div class="weui-media-box weui-media-box_appmsg">
                    <div class="weui-media-box__bd">
                        <h4 class="weui-media-box__title">{{drugdetail[0].payer}}</h4>
                        <p class="desc">门诊号：{{drugdetail[0].patid}}</p>
                        <p class="desc">科室：全科</p>
                        <p class="desc">性别：{{drugdetail[0].sex}}</p>
                        <p class="desc">年龄：{{drugdetail[0].years}}</p>
                        <p class="desc">住址：{{drugdetail[0].addr}}</p>
                        <p class="desc">流水号：{{drugdetail[0].sn}}</p>
                        <p class="desc">开药时间：{{drugdetail[0].dt}}</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="weui-panel weui-panel_access my-panel" v-for="item in drugdetail">
            <div class="weui-cells weui-cells_checkbox">
                <label class="weui-cell weui-check__label" >
                    <div class="weui-cell__hd">
                        <input type="checkbox" class="weui-check" checked @change="checkdrug(item, $event)" name="checkbox1">
                        <i class="weui-icon-checked"></i>
                    </div>
                    <div class="weui-cell__bd">
                        <p>{{item.gn}}</p>
                    </div>
                </label>
            </div>
            <div class="weui-form-preview my-preview">
                <div class="weui-form-preview__bd">
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">产地</label>
                        <span class="weui-form-preview__value">{{item.made}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">规格</label>
                        <span class="weui-form-preview__value">{{item.spr}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">单位</label>
                        <span class="weui-form-preview__value">{{item.utr}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">批号</label>
                        <span class="weui-form-preview__value">{{item.bn}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">有效期</label>
                        <span class="weui-form-preview__value">{{item.vdate}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">类型</label>
                        <span class="weui-form-preview__value">{{item.typ}}</span>
                    </div>
                    <div class="weui-form-preview__item" >
                        <label class="weui-form-preview__label">数量</label>
                        <span class="weui-form-preview__value">{{item.quan}}</span>
                    </div>
                    <div class="weui-form-preview__item" v-if="item.typ=='中草药'">
                        <label class="weui-form-preview__label">付数</label>
                        <span class="weui-form-preview__value">{{item.cs}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">单价</label>
                        <span class="weui-form-preview__value">{{item.prr}}</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">金额</label>
                        <span class="weui-form-preview__value">{{jsxs(item)}}</span>
                    </div>
                </div>
            </div>
        </div>

        <p class="weui-btn-area">
            <a class="weui-btn weui-btn_primary" href="#" @click="senddrug">确认</a>
        </p>
    </div>
</div>
<!--scripts-->
<script src="js/main.js"></script>

<script>
    $(function () {
        function getparam(url, paramname) {
            if (url.indexOf(paramname) != -1) {
                var pos_start = url.indexOf(paramname) + paramname.length + 1;
                var pos_end = url.indexOf("&", pos_start);

                if (pos_end == -1) {
                    return url.substring(pos_start)
                } else {
                    return url.substring(pos_start, pos_end)
                }
            }
        }
        var inventorydetail = new Vue({
            el: '#prescription-drugs-detail',
            computed: {
                drugdetail: function () {
                    var str = window.location.search;
                    let aid = getparam(str, 'aid')
                    let patid = getparam(str, 'patid')
                    let sn = getparam(str, 'sn')

                    console.info(aid+patid)
                    //查询发药详细记录
                    let res = []
                    ajaxsync({
                        url: '/mph/rec/one?aid='+aid+'&patid='+patid+'&sn='+sn,
                        method: 'get',
                        datajson: null,
                        succ: function (data) {
                            res = data.clinicRecViews
                        }
                    })
                    return res
                }
            },
            methods: {
                senddrug(){
                    console.info(this.drugdetail)
                    if(this.drugdetail.length == 0){
                        $.alert("请选择要发的药品");
                        return false
                    }
                    let drugs = this.drugdetail.filter(n => {
                        if(n.check == false){
                            return false
                        }
                        return true
                    })
                    let fdrugs = []
                    for(let i=0; i<drugs.length; i++){
                        fdrugs[i] = {
                            aid: drugs[i].aid,
                            patid: drugs[i].patid,
                            sn: drugs[i].sn,
                            ord: drugs[i].ord,
                            auid: drugs[i].auid,
                        }
                    }
                    $.confirm({
                        title: '确认发药',
                        text: '您确认发放药品吗？',
                        onOK: function () {
                            ajaxsync({
                                url: '/mph/rec/dispensing',
                                method: 'post',
                                datajson: fdrugs,
                                succ: function (data) {
                                    $.toast("操作成功", function () {
                                        location.href = 'prescription-drugs.html'
                                    });

                                }
                            })
                        },
                        onCancel: function () {
                            return false
                        }
                    });

                },
                checkdrug(druginfo, event){
                    console.info(event)
                    if(!event.target.checked){
                        druginfo.check = false
                    }else{
                        druginfo.check = true
                    }
                },
                jsxs(item){
                    let cc = item.mny*item.cs
                    let aNew;
                    let re = /([0-9]+\.[0-9]{2})[0-9]*/;
                    aNew = (cc+'').replace(re,"$1");
                    return aNew
                }
            }
        })
    })
</script>

</body>
</html>
